<template>
	<view style="background: #FFFFFF !important;">
		<view style="padding: 15rpx 15rpx;">
			<u-icon name="calendar-fill" size="30" color="#909399"></u-icon>
			<text
				style="font-size: 24rpx;font-family: PingFang SC-Medium, PingFang SC;font-weight: 500;color: #666666;">{{shopDetail.shop_name}}</text>
		</view>
		<view >
			<text
				style="padding: 15rpx 30rpx;font-size: 40rpx;font-family: PingFang SC-Bold, PingFang SC;font-weight: bold;color: #333333;">{{taocanDetail.title}}</text>
			<view>
				<image :src="'https://oss.bigchun.com' + taocanDetail.image" style="width: 100%;border-radius: 0px;">
				</image>
			</view>
		</view>
		<view style="display: flex;padding: 15rpx 30rpx;border-bottom: 2rpx solid #f1f1f1;">
			<u-rate :value="shopDetail.shop_score" activeColor="#FE811C" :disabled="true"></u-rate>
			<view @click="toComment"
			style="font-size: 24rpx;font-weight: 500;color: #777777;text-align: end;width: -webkit-fill-available;">共{{commentLists.length}}个消费评价></view>
		</view>
		<view  style="margin: 15rpx 30rpx;border-bottom: 2rpx solid #f1f1f1;">
			<text class="cu-item flex-sub tabcolor cur" style="border-bottom: 6rpx solid #FC5351;">
				套餐信息
			</text>
		</view>
		<view style="margin-bottom: 70rpx">
<!--			<view v-html="taocanDetail.content" style="height: 50vh;">-->
<!--			</view>-->
      <u-parse :html="taocanDetail.content"></u-parse>
		</view>
		<view style="display: flex;padding: 10rpx 20rpx 20rpx 20rpx;align-items: center; position:fixed;bottom: 0" v-if="taocanType === 'huiyuan'">
			<text style="width: 200rpx;font-size: 32rpx;font-family: PingFang SC-Bold, PingFang SC;font-weight: bold;color: #FC5351;">￥{{taocanDetail.vip_price}}</text>
			<text style="width: 350rpx;font-size: 24rpx;font-family: PingFang SC-Medium, PingFang SC;font-weight: 500;color: #999999;">门市价：￥{{taocanDetail.original_price}}</text>
			<view class="submit" style="text-align: end;width: -webkit-fill-available;">
				<text @click="toPay" style="font-size: 14px;font-family: PingFang SC-Medium, PingFang SC;font-weight: 500;color: #FFFFFF;background: #FC5351;border-radius: 20px;padding:18rpx 30rpx;">
          {{ isVip?'立即抢购':'会员专享' }}</text>
			</view>
		</view>

	</view>
</template>

<script>
	import https from '@/shopro/requests/index'
	// import wxsdk from '@/shopro/wechat/sdk'
	// var jweixin = require("jweixin-module");
	// import Pay from '@/shopro/pay';

	export default {
		data() {
			return {
				taocanId: '',
				shopDetail: null,
				commentLists: null,
				taocanDetail: null,
				taocanType: null,
				title: null,
        isVip:0//0非会员  1会员
			};
		},
		onLoad(options) {
			this.taocanId = options.taocanId
			this.taocanType = options.taocanType
			this.store_shop_id = options ? options.id : getCurrentPages()[0].options.id
			this.title = decodeURIComponent(options.title)
			uni.setNavigationBarTitle({
				title: this.title
			});
			this.init();
			// this.getCommentLists();
		},
		methods: {
			async init() {
				console.log("=========shopDetail")
				var that = this;
				that.$https('category.shopDetail', {
						token: uni.getStorageSync("token"),
						store_shop_id: this.store_shop_id,
						latitude: uni.getStorageSync("latitude"),
						longitude: uni.getStorageSync("longitude")
					})
					.then(res => {
						if (res.code === 1) {
							that.shopDetail = res.data;
							console.log(that.taocanType)
							if (that.taocanType === 'huiyuan') {
								that.taocanDetail = that.shopDetail.store_goods.find(item => item.id == that
									.taocanId)
							} else {
								that.taocanDetail = that.shopDetail.platform_goods.find(item => item.id == that
									.taocanId)
							}
							console.log("！！！！！！！！！！！！！！！")
							console.log(that.taocanDetail)
							that.getCommentLists()
              this.getVip()
						}
					});
			},
			getCommentLists() {
				console.log("=========commentLists")
				var that = this;
				that.$https('category.commentLists', {
						token: uni.getStorageSync("token"),
						store_shop_id: that.store_shop_id,
						goods_id:that.taocanDetail.id
					})
					.then(res => {
						console.log("*****************--", res);
						if (res.code === 1) {
							that.commentLists = res.data.data;

						}
					});
			},
			toComment(){
				uni.navigateTo({
					url: '/pages/index/category/commentList?store_shop_id=' + this.store_shop_id +"&goods_id=" + this.taocanDetail.id
				})
			},
			async toPay(){
				var that = this;
        if(!that.isVip){
          that.$u.toast('成为会员后，才可以享受');
          return
        };
				https('common.cate_order', {
					cash_money: that.taocanDetail.vip_price,
					goods_id: that.taocanDetail.id,
					store_shop_id:that.store_shop_id,
					goods_num:1
				}, '加载中...').then(res => {
					if (res.code === 1) {
						if(that.taocanDetail.vip_price === 0){
							that.$u.toast('支付成功')
							uni.navigateTo({
								url: '/pages/order/cate/cateList'
							})
						}else{
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.data.timeStamp,
								nonceStr: res.data.nonceStr,
								package: res.data.package,
								signType: res.data.signType,
								paySign: res.data.paySign,
								success: (payRes) => {
									uni.showModal({
										content: '支付成功',
										title: '提示',
										success: res => {
											uni.navigateTo({
												url: '/pages/order/cate/cateList'
											})
										}
									})

								},
								fail: () => {
									this.$u.toast('支付失败，请重试')
								}
							})
						}
					}
				});
			},
      getVip() {
        this.$https('user.isVip').then(res => {
          if (res.code === 1) {
            this.isVip = res.data;
          }
        })
      },
		}
	}
</script>

<style lang="scss">
	.cu-item.cur {
		border-bottom: 4rpx solid #FD5755;
	}

	.tabcolor {
		// color: #000000;
		font-weight: bold;
		color: #333333;
		font-size: 14px;
	}
</style>
